import { getProjects, getUserProperties,getEventProperties, getEventList } from "@/api/projectManage";

const projectManage  = {
	namespaced: true,
	state: {
		paginationConfig: {
			current : 1,
			pageSize: 100,
			total: 0,
			pageSizeOptions: ['10', '30', '50', '100'],
			showQuickJumper: true,
			showSizeChanger: true,
			showTotal : (total)=>{
				let pageConfig = projectManage.state.paginationConfig
				return `共  ${total}  条记录   第  ${pageConfig.current} / ${Math.ceil(pageConfig.total/pageConfig.pageSize)}  页 `
			}
		},
		order: 'desc',
		orderBy: 'createdAt',
		allUsers: [],
		eventList: [],
		projectId: ''
	},
	mutations: {
		setTotal: (state, total) => {
			state.paginationConfig.total = total
		},
		setPage: (state, current) => {
			state.paginationConfig.current = current
		},
		setPageSize: (state, pageSize) => {
			state.paginationConfig.pageSize = pageSize
		},
		setOrder: (state, order) => {
			state.order = order
		},
		setOrderBy: (state, orderBy) => {
			state.orderBy = orderBy
		},
		setEventList: (state, eventList) => {
			state.eventList = eventList
		},
		setCurrentProjectId: (state, id) => {
			state.projectId = id;
		},
	},
	actions: {
		getProjectList({ state, commit }) {
			return new Promise((resolve, reject) => {
				getProjects()
					.then(res => {
						if(res.status) {
							const data = res.data
							resolve(data)
						} else {
							reject(res)
						}
					}).catch(error => {
					reject(error)
				})
			})
		},
		getEventList({ state, commit }, projectId) {
			return new Promise((resolve, reject) => {
				getEventList(projectId)
					.then(res => {
						if(res.status) {
							const data = res.data
							resolve(data)
						} else {
							reject(res)
						}
					}).catch(error => {
					reject(error)
				})
			})
		},
		getUserProperties({ state, commit }, projectId) {
			return new Promise((resolve, reject) => {
				getUserProperties(projectId)
					.then(res => {
						if(res.status) {
							const data = res.data
							resolve(data)
						} else {
							reject(res)
						}
					}).catch(error => {
					reject(error)
				})
			})
		},
		getEventProperties({ state, commit }, projectId) {
			return new Promise((resolve, reject) => {
				getEventProperties(projectId)
					.then(res => {
						if(res.status) {
							const data = res.data
							resolve(data)
						} else {
							reject(res)
						}
					}).catch(error => {
					reject(error)
				})
			})
		}

	},

	getters: {

	}
}

export default projectManage
